// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2019-2025, The OpenROAD Authors

#pragma once

#include "dbCore.h"
#include "odb/dbId.h"
#include "odb/dbTypes.h"
#include "odb/dbViaParams.h"
#include "odb/odb.h"

namespace odb {

class _dbBox;
class _dbTechLayer;
class _dbTechViaGenerateRule;
class _dbTechNonDefaultRule;
class _dbDatabase;
class dbIStream;
class dbOStream;

struct _dbTechViaFlags
{
  uint default_via : 1;
  uint top_of_stack : 1;
  uint has_params : 1;
  uint spare_bits : 29;
};

class _dbTechVia : public _dbObject
{
 public:
  _dbTechVia(_dbDatabase*, const _dbTechVia& v);
  _dbTechVia(_dbDatabase*);
  ~_dbTechVia();

  bool operator==(const _dbTechVia& rhs) const;
  bool operator!=(const _dbTechVia& rhs) const { return !operator==(rhs); }
  void collectMemInfo(MemInfo& info);

  // PERSISTANT-MEMBERS
  _dbTechViaFlags flags_;
  double resistance_;
  char* name_;
  char* pattern_;
  dbId<_dbBox> bbox_;  // Caching the bbox speeds up defin imports.
  dbId<_dbBox> _boxes;
  dbId<_dbTechLayer> top_;     // Caching the layer speeds up defin imports.
  dbId<_dbTechLayer> bottom_;  // Caching the layer speeds up defin imports.
  dbId<_dbTechNonDefaultRule> non_default_rule_;
  // via generated by tech-via-rule, 5.6 DEF
  dbId<_dbTechViaGenerateRule> generate_rule_;
  _dbViaParams via_params_;  // params used to generate this via, 5.6 DEF
  dbId<_dbTechVia> next_entry_;
};

dbOStream& operator<<(dbOStream& stream, const _dbTechVia& via);
dbIStream& operator>>(dbIStream& stream, _dbTechVia& via);

}  // namespace odb
